package com.ruoyi.common.flowable.execution;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.mapper.ActHiProcinstMapper;
import jakarta.annotation.Resource;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.common.engine.api.delegate.event.FlowableEventType;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.impl.persistence.entity.HistoricProcessInstanceEntityImpl;
import org.flowable.engine.task.Comment;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public class MyFlowableEventListener implements FlowableEventListener {
    @Autowired
    protected ActHiProcinstMapper actHiProcinstMapper;
    @Resource
    protected TaskService taskService;
    @Resource
    protected RuntimeService  runtimeService;
    /**
     * 获取id
     * */
    protected String getId(HistoricProcessInstanceEntityImpl taskEntity){
        String processInstanceId = taskEntity.getProcessInstanceId();
        Map vars = runtimeService.getVariables(processInstanceId);
        String id = StrUtil.toString(vars.get("id"));
        return id;
    }
    @Override
    public void onEvent(FlowableEvent event) {

    }

    @Override
    public boolean isFailOnException() {
        return false;
    }

    @Override
    public boolean isFireOnTransactionLifecycleEvent() {
        return false;
    }

    @Override
    public String getOnTransaction() {
        return null;
    }

    @Override
    public Collection<? extends FlowableEventType> getTypes() {
        return FlowableEventListener.super.getTypes();
    }
}
